package com.yulongtian.weekCompetition.month202301.week04;

import java.util.Arrays;
import java.util.Comparator;

/**
 * 可
 *
 * @author yulongTian
 * @create 2023-01-22 10:22
 */
public class Test02 {
    public static void main(String[] args) {
        int[][] score = {{10, 6, 9, 1}, {7, 5, 11, 2}, {4, 8, 3, 15}};
        int k = 2;
        System.out.println(Arrays.deepToString(sortTheStudents(score, k)));
    }

    public static int[][] sortTheStudents(int[][] score, int k) {
        int m = score.length;
        int n = score[0].length;
        int[][] ans = new int[m][n];
        int[][] order = new int[m][2];
        for (int i = 0; i < m; i++) {
            order[i][0] = score[i][k];
            order[i][1] = i;
        }
        Arrays.sort(order, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return o2[0] - o1[0];
            }
        });
        for (int i = 0; i < m; i++) {
            ans[i] = score[order[i][1]];
        }
        return ans;
    }

}
